package com.uton.rfidcontroller.view.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * Created by SEELE on 2017/3/22.
 * ViewPager通用适配器
 */

public class BankingContentAdapter extends FragmentPagerAdapter {

    private ArrayList<Fragment> mData;
    private Fragment currentFragment;

    public void setData(ArrayList<Fragment> data) {
        mData = data;
        notifyDataSetChanged();
    }

    public BankingContentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return mData.get(position);
    }

    @Override
    public int getCount() {
        return mData != null && mData.size() != 0 ? mData.size() : 0;
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        super.setPrimaryItem(container, position, object);
        currentFragment = (Fragment) object;
    }

    public Fragment getCurrentFragment() {
        return currentFragment;
    }

    public int getCurrentFragmentId() {
        for (int i = 0; i < mData.size(); i++) {
            if (currentFragment==mData.get(i)){
                return i;
            }
        }
        return -1;
    }


}
